// pages/dingdan22/dingdan22.js
const time = require('../../util/uts.js')
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderInfo: null,
    dadada: 1,
    curordernum: '',
    userId: '',
    taskId: null,
    rizhi: '',//日志输入内容
  },
  // 获取文本输入框内容
  wenben: function (e) {
    this.setData({
      rizhi: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;

    that.setData({
      dadada: app.globalData.forsysuser_id,
      userId: options.userId,
      taskId: options.taskId,
      curordernum: options.ordernum
    })
    
    wx.request({
      url: app.globalData.serviceUrl + '/wcComOrder/getWcComOrderForUserId',
      data: {
        userId: that.data.userId
      },
      method: "GET",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success(res) {
        if(res.data.success) {
          that.setData({
            orderInfo: res.data.data,
            curordernum: res.data.data.ordernum
          });
        }

        if (res.data.status == 'statu_01') {
          wx.showModal({
            title: '提示',
            content: '是否认领此单',
            success: function (res) {
              if (res.confirm) {
                console.log("点击确认")
                wx.request({
                  url: app.globalData.serviceUrl + '/wcComOrder/updateWcComOrderStatus',
                  method: 'POST',
                  header: {
                    "Content-Type": "application/x-www-form-urlencoded",
                  },
                  data: {
                    userId: options.userId,
                    status: 'statu_02'
                  },
                  success(res) {
                    if (res.data) {
                      wx.showModal({
                        title: '提示',
                        content: '认领成功！',
                        showCancel: false,
                        success: function (res) {
                          wx.reLaunch({
                            url: '../dingdan22/dingdan22?userId=' + options.userId,
                          })
                        }
                      });
                    } else {
                      wx.showModal({
                        title: '提示',
                        content: '认领失败！',
                        showCancel: false,
                      });
                    }
                  }
                })
              } else {
                console.log("取消")
              }
            }
          });
        }
      }
    })


    // wx.request({
    //   url: app.globalData.serviceUrl + '/wcComOrder/getWcComOrderForUserId',
    //   data: {
    //     userId: that.data.userId
    //   },
    //   method: "GET",
    //   header: {
    //     'content-type': 'application/x-www-form-urlencoded'
    //   },
    //   success(res) {
    //     var data1 = res.data.data.ordernum;

    //     that.setData({
    //       ordernum: data1
    //     });
    //     console.log(res.data);

    //   }
    // });

  },

  jiben: function () {
    wx.navigateTo({
      url: '../../order/basic/basic?orderId=' + this.data.curordernum
    })
  },
  contacts: function () {
    wx.navigateTo({
      url: '../../order/contacts/contacts?orderId=' + this.data.curordernum
    })
  },
  vehicle: function () {
    wx.navigateTo({
      url: '../../order/vehicle/vehicle?orderId=' + this.data.curordernum
    })
  },
  work: function () {
    wx.navigateTo({
      url: '../../order/work/work?orderId=' + this.data.curordernum
    })
  },
  gongzuo: function () {
    wx.navigateTo({
      url: '../../order/work/work'
    })
  },
  lianxiren: function () {
    wx.navigateTo({
      url: '../../order/contacts/contacts'
    })
  },
  car: function () {
    wx.navigateTo({
      url: '../../order/vehicle/vehicle'
    })
  },
  addimg: function () {
    wx.navigateTo({
      url: '../../order/image/image?orderId=' + this.data.curordernum
    })
  },
  // rizhi: function () {
  //   wx.navigateTo({
  //     url: '../../order/rizhi2/rizhi2'
  //   })
  // },
  fengkong: function () {
    wx.navigateTo({
      url: '../../order/inquire/inquire?orderId=' + this.data.curordernum
    })
  },
  yinhangka: function () {
    wx.navigateTo({
      url: '../../order/inquire2/inquire2?orderId=' + this.data.curordernum
    })
  },
  danwei: function () {
    wx.navigateTo({
      url: '../../order/inquire3/inquire3?orderId=' + this.data.curordernum
    })
  },


  reject: function () {
    var that = this;

    if(that.data.rizhi == "") {
      wx.showToast({
        title: '驳回时，必须填写驳回原因！',
        icon: 'none'
      })

      return;
    }

    wx.request({
      url: app.globalData.serviceUrl + '/wcComOrder/complete',
      data: {
        pass: false,
        comment: that.data.rizhi,
        taskId: that.data.taskId
      },
      method: "GET",
      success(res) {
        if (res.data.success) {
          wx.showToast({
            title: '提交成功',
            icon: 'none'
          })

        } else {
          wx.showToast({
            title: '提交失败:' + res.data.errorMsg,
            icon: 'none'
          })
        }
      }
    })
  },

  tijiao: function () {
    var that = this;
    
    wx.request({
      url: app.globalData.serviceUrl + '/wcComOrder/complete',
      data: {
        pass: true,
        comment: that.data.rizhi,
        taskId: that.data.taskId
      },
      method: "GET",
      success(res) {
        if (res.data.success) {
          wx.showToast({
            title: '提交成功',
            icon: 'none'
          })

        } else {
          wx.showToast({
            title: '提交失败:' + res.data.errorMsg,
            icon: 'none'
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})